package com.purong.purong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.bean.BankLoanRecordBean;
import com.purong.purong.widget.RadiusImageView;
import com.yao.sdk.glide.GlideUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zengwenjie on 2017/12/8.
 */
public class BankLoanRecordAdapter extends RecyclerView.Adapter<BankLoanRecordAdapter.ViewHolder> {
    private List<BankLoanRecordBean> recordList=new ArrayList<>();
    private Context mContext;
    private OnRecordListener mListener;
    public BankLoanRecordAdapter(Context context) {
        this.mContext = context;
    }
    public void setData(List<BankLoanRecordBean> list) {
        this.recordList = list;
    }
    public void setOnRecordListener(OnRecordListener listener){
        this.mListener=listener;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.bank_loan_record_item, parent, false);
        // set the view's size, margins, paddings and item_circle parameters
        ViewHolder vh = new ViewHolder(v);

        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        GlideUtil.getInstance().load(mContext,recordList.get(position).getLoan_agency_thumb(),holder.img,true);
        holder.name.setText(recordList.get(position).getLoan_product_name());
        holder.date.setText("申请时间: "+recordList.get(position).getLoan_apply_time().split(" ")[0]);
        holder.money.setText(recordList.get(position).getApply_money());
        holder.period.setText(recordList.get(position).getApply_period());
        holder.period.setText(recordList.get(position).getApply_period());
        holder.status.setText(recordList.get(position).getLoan_apply_status_name());
        if (recordList.get(position).getLoan_apply_status().equals("1")){
            holder.status.setTextColor(mContext.getResources().getColor(R.color.green));
        }else if (recordList.get(position).getLoan_apply_status().equals("2")){
            holder.status.setTextColor(mContext.getResources().getColor(R.color.blue));
        }else if (recordList.get(position).getLoan_apply_status().equals("3")){
            holder.status.setTextColor(mContext.getResources().getColor(R.color.red));
        }else {
            holder.status.setTextColor(mContext.getResources().getColor(R.color.text_gray));
        }
        holder.mainLay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener!=null){
                    mListener.onRecordClick(position);
                }
            }
        });
    }
    public  class ViewHolder extends RecyclerView.ViewHolder {
        //绑定每个CircleItem的控件引用到ViewHolder
        private RadiusImageView img;
        private TextView name,money,period,date,status;
        private LinearLayout mainLay;
        public ViewHolder(View v) {
            super(v);
            mainLay=(LinearLayout)v.findViewById(R.id.main_lay);
            img=(RadiusImageView)v.findViewById(R.id.img);
            name=(TextView)v.findViewById(R.id.name);
            money=(TextView)v.findViewById(R.id.money);
            period=(TextView)v.findViewById(R.id.period);
            date=(TextView)v.findViewById(R.id.date);
            status=(TextView)v.findViewById(R.id.status);



        }
    }
    @Override
    public int getItemCount() {
        return recordList.size();
    }
    public interface OnRecordListener{
        void onRecordClick(int position);
    }
}
